package com.itc.bi.xxljob;

import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSONObject;
import com.itc.bi.entity.DatasourceEntity;
import com.itc.bi.service.DatasourceService;
import com.itc.bi.service.TableService;
import com.itc.bi.service.impl.DataSetXxlBobService;
import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @BelongsProject: itc-airport-cloud
 * @BelongsPackage: com.itc.bi.xxljob
 * @Author: xuzy
 */
@Slf4j
@Component
public class DataSourceXxlJob {
    @Autowired
    private DatasourceService datasourceService;
    @Autowired
    TableService tableService;

    /**
     * sql数据同步方法
     * @throws Exception
     */
    @XxlJob("datasourceHandler")
    public void datasourceHandler()throws Exception{
        log.debug("xxl更新数据源下表结构信息-开始");
        List<DatasourceEntity> list = datasourceService.list();
        list.stream().forEach( source -> {
            try {
                tableService.updateByDatasourceId(source.getId());
            }catch (Exception e){
                log.error("更新数据源{}失败,异常信息:{}",source.getId(),e.getMessage());
            }
        });
        log.debug("xxl更新数据源下表结构信息-结束");
    }
}
